<template>
	<view class="container" :class="skinStyle">
		<!-- <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading="false"></tui-skeleton> -->
		<!-- 普通订单详情 -->

		<view class="tui-skeleton">
			<view class="tui-order-header">
				<view class="tui-header-content theme-gradient-bg tui-skeleton-fillet">
					<view>
						<view class="tui-status-text">{{ getStatusLabel(status) }}</view>
						<view class="tui-reason">
							<text class="tui-reason-text">{{ getReason(status) }}</text>
							<tui-countdown
								:time="paymentTime"
								color="rgba(254,254,254,0.75)"
								colonColor="rgba(254,254,254,0.75)"
								bcolor="transparent"
								bgcolor="transparent"
								v-if="status === 1"
								@end="endOfTime"
							></tui-countdown>
						</view>
					</view>
					<view class="tui-status-img iconfont" :class="iconClass"></view>
				</view>
			</view>
			<view class="">
				<!-- <tui-list-cell :hover="false" :lineLeft="false"><view class="tui-goods-title tui-skeleton-fillet">自提地址</view></tui-list-cell> -->
				<view class="tui-order-item ">
					<view class="tui-order-content" style="position: relative;">
						<view class="tui-flex-box">
							<text class="tui-icon-img iconfont icondizhi"></text>
							<view class="tui-addr">
								<view class="tui-addr-userinfo">
									{{ pickupName }}
									<text class="tui-addr-tel pickupMobile">{{ pickupMobile }}</text>
								</view>
								<view class="tui-addr-text">{{ areaLevel1 }}{{ areaLevel2 }}{{ areaLevel3 }}{{ addressDet }}</view>
							</view>
						</view>
						<view class="tui-bg-img"></view>
					</view>
				</view>
			</view>
			<view class="tui-order-item ">
				<view class="tui-order-content">
					<view class="tui-goods-title tui-skeleton-fillet" style="background-color: #FFFFFF;padding-bottom: 10rpx;border-bottom: 1px solid #F2F2F2;">商品信息</view>
				</view>
				<view v-for="(item, index) in goodsData" :key="index">
					<block v-if="item.show !== 2">
						<tui-list-cell :hover="false" padding="0">
							<view class="tui-goods-item" @tap="detail(item)">
								<image src="../../../static/img/freeShipping.png" class="tui-goods-img imgMark" v-if="item.isSample === 0 && item.isParcel === 1"></image>
								<image src="../../../static/img/gift.png" class="tui-goods-img imgMark" v-if="item.isSample !== 0"></image>
								<image :src="imgSrc + item.suitProductThumbnailImageUrl" v-if="item.isSuit" class="tui-goods-img"></image>
								<image :src="imgSrc + item.productThumbnailImageUrl" v-else class="tui-goods-img"></image>
								<view class="tui-goods-center">
									<view class="tui-goods-name" v-if="item.isSuit">{{ item.suitName }}</view>
									<view class="tui-goods-name" v-else>{{ item.productName }}</view>
									<view class="tui-goods-attr" v-if="item.isSuit"></view>
									<view class="tui-goods-attr" v-else>{{ item.specificationName }}</view>
								</view>
								<view class="tui-price-right">
									<view v-if="item.isSuit">￥{{ (item.suitRealAmount / item.suitCount) | moneyFormat(item.suitRealAmount / item.suitCount) || '0' }}</view>
									<view v-else>￥{{ (item.realAmount / item.productsCount) | moneyFormat(item.realAmount / item.productsCount) || '0' }}</view>
									<view v-if="item.isSuit">x{{ item.suitCount }}</view>
									<view v-else>x{{ item.productsCount }}</view>
								</view>
							</view>
						</tui-list-cell>
					</block>
				</view>
				<view class="tui-goods-info">
					<view class="tui-skeleton-fillet">
						<view class="tui-price-flex tui-size24">
							<view>商品总额</view>
							<view>￥{{ orderAmount | moneyFormat(orderAmount) }}</view>
						</view>
						<view class="tui-price-flex tui-size24">
							<view>运费</view>
							<view>{{ logisticsCost }}</view>
						</view>

						<view class="tui-price-flex tui-size32 tui-pbtm20">
							<view class="tui-flex-shrink">合计</view>
							<view class="tui-goods-price">
								<view class="tui-size-24">￥</view>
								<view class="tui-price-large">{{ realAmount }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="tui-order-item " v-if="preSaleFlag == 1">
				<tui-list-cell :hover="false">
					<view class="tui-padding tui-flex" :class="{ redRow: orderPreSaleStatus == 1 }">
						<view>阶段1 定金 ￥{{ depositPrice }}</view>
						<view>预售商品定金不退哦</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false">
					<view class="tui-padding tui-flex" :class="{ redRow: orderPreSaleStatus == 2 }">
						<view>阶段2 尾款 ￥{{ balance }}</view>
						<view>{{ balanceTime }}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false">
					<view class="tui-padding tui-flex" :class="{ redRow: orderPreSaleStatus == 3 }">
						<view>阶段3 发货时间</view>
						<view>{{ deliverTime }}</view>
					</view>
				</tui-list-cell>
			</view>
			<view class="tui-order-item">
				<view class="tui-order-content">
					<view class="tui-skeleton-fillet">
						<view class="tui-goods-title tui-skeleton-fillet" style="background-color: #FFFFFF;padding-bottom: 10rpx;border-bottom: 1px solid #F2F2F2;">订单信息</view>
						<view class="tui-order-flex" v-if="buyComment != '' && buyComment != null">
							<view class="tui-item-title">订单备注:</view>
							<view class="tui-item-content">{{ buyComment }}</view>
						</view>
						<view class="tui-order-flex">
							<view class="tui-item-title">订单号:</view>
							<view class="tui-item-content">{{ orderSerial }}</view>
						</view>
						<view class="tui-order-flex">
							<view class="tui-item-title">下单时间:</view>
							<view class="tui-item-content">{{ createTime }}</view>
						</view>
						<view class="tui-order-flex" v-if="payDate">
							<view class="tui-item-title">付款时间:</view>
							<view class="tui-item-content">{{ payDate }}</view>
						</view>
						<view class="tui-order-flex" v-if="deliveryDate">
							<view class="tui-item-title">发货时间:</view>
							<view class="tui-item-content">{{ deliveryDate }}</view>
						</view>
					</view>
				</view>
			</view>
			<view @tap="jumpToService" class="service">
				<view class="iconfont iconkefu"></view>
				<view class="serviceWord">联系卖家</view>
			</view>
		</view>
		<view class="tui-safe-area"></view>
		<view class="tui-skeleton-fillet">
			<view class="tui-tabbar tui-order-btn tui-skeleton-fillet" v-if="status === 0">
				<view class="tui-btn-mr" v-if="orderPreSaleStatus != 2 && orderPreSaleStatus != 1">
					<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="show">取消订单</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="orderPreSaleStatus == 2 && timeLimit()">
					<tui-button type="primary" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="goPay">去付款</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="orderPreSaleStatus != 2">
					<tui-button type="primary" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="goPay">去付款</tui-button>
				</view>
			</view>
			<view class="tui-tabbar tui-order-btn tui-skeleton-fillet" v-else>
				<view class="tui-btn-mr" v-if="status !== 70 && status !== 100 && checkReturn()">
					<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="applyService()">申请售后</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="status !== 10 && status !== 70 && status && status !== 100">
					<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="getlogistics()">查看物流</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="status == 30">
					<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="show2">确认收货</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="status == 40">
					<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="appraise('0')">去评价</tui-button>
				</view>
				<view class="tui-btn-mr" v-if="status == 60 && addCommentFlg == 0">
					<tui-button type="primary" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="appraise('1')">追加评价</tui-button>
				</view>
			</view>
		</view>
		<tui-modal :show="modalShow" @click="handleClick" @cancel="hide" title="提示" :content="modalContent"></tui-modal>
		<loading v-if="isLoading"></loading>
		<tui-modal></tui-modal>
	</view>
</template>

<script>
import tuiButton from '@/components/button/button';
import tuiCountdown from '@/packageA/components/countdown/countdown';
import tuiListCell from '@/components/list-cell/list-cell';
import mixin from '@/utils/mixin.js';
import tuiSkeleton from '@/packageA/components/tui-skeleton/tui-skeleton';
export default {
	mixins: [mixin],
	components: {
		tuiButton,
		tuiCountdown,
		tuiListCell,
		tuiSkeleton
	},
	data() {
		return {
			imgSrc: this.$store.state.imgUrl,
			isLoading: true,
			status: undefined, //1-待付款 2-已支付 3-备货中 4-待自提 5-已完成 6.已取消
			orderId: '',
			iconClass: '',
			iconArr: ['iconweibiaoti2fuzhi04', 'iconzhangdan', 'iconbeihuodan', 'iconmendianzitidaihexiaosvg', 'iconyiwancheng2', 'iconyiquxiao1'],
			iconArrPostSale: ['iconshenhe', 'icontuihuo', 'iconyichuli', 'iconjujue', 'iconicon_function_fangqi'],
			orderDetail: {},
			postSaleDetail: {},
			reasonArray: ['', '商品发货有误', '商品质量问题', '服务问题'],
			handleWay: ['', '退款', '退货退款', '原规格免费送一份'],
			postSaleMode: '',
			postSaleStatus: '',
			loadMake: true,
			qrVal: '',
			unit: 'upx',
			paymentTime: 0,
			orderCancelFlg: '',
			modalShow: false,
			modalContent: '',
			statusFlg: '',
			skeletonShow: true,
			pickupName: '',
			pickupMobile: '',
			addressDet: '',
			orderAmount: '',
			logisticsCost: '',
			couponPrice: null,
			couponName: null,
			realAmount: '',
			orderSerial: '',
			createTime: '',
			payDate: '',
			deliveryDate: '',
			goodsData: [],
			version: '',
			areaLevel1: '',
			areaLevel2: '',
			areaLevel3: '',
			orderPreSaleStatus: '',
			nowDate: '',
			preSaleAfterPaymentStartTime: '',
			preSaleAfterPaymentEndTime: '',
			depositPrice: '',
			balance: 0,
			balanceTime: '',
			deliverTime: '',
			buyComment: '',
			preSaleAfterPaymentStartDay: '',
			preSaleAfterPaymentDateType: '',
			discountAmount: '',
			expressFee: '',
			saleAmount: null,
			productAmount: '',
			list: '',
			remainHour: '',
			remainDay: '',
			preSaleFlag: undefined,
			addCommentFlg: 0,
			couponPacleName:null,
			stopFunctionArr: [],
		};
	},
	onLoad(options) {
		// #ifdef H5
		this.$wechat.noShare();
		// #endif
		console.log(options);
		if (options) {
			this.qrVal = options.id;
		}
		this.stopFunctionArr = this.$store.state.dictDataAll['stopFunction'];
	},
	onShow() {
		this.getOrderDetail();
	},
	filters: {
		moneyFormat(num) {
			var result = parseFloat(num);
			result = Math.round(num * 100) / 100;
			var s_x = result.toString();
			var pos_decimal = s_x.indexOf('.');
			if (pos_decimal < 0) {
				pos_decimal = s_x.length;
				s_x += '.';
			}
			while (s_x.length <= pos_decimal + 2) {
				s_x += '0';
			}
			return s_x;
		},
		mathFloor(num) {
			var num1 = parseFloat(num).toFixed(3);
			var result = Math.floor(num1 * 100) / 100;
			if (result < 0.01) {
				result = 0.01;
			}
			return result;
		}
	},
	methods: {
		moneyFormat(num) {
			var result = parseFloat(num);
			result = Math.round(num * 100) / 100;
			return result;
		},
		appraise(type) {
			let stopFunItem1 = null; //当前对象
			let stopFunItem2 = null; //message对象
			let stopFunItemArr = this.stopFunctionArr.filter((item) => {
				return (item.dictLabel == 'function5' || item.dictLabel == 'message')
			});
			if (stopFunItemArr[0].dictLabel == 'function5') {
				stopFunItem1 = stopFunItemArr[0];
				stopFunItem2 = stopFunItemArr[1];
			} else {
				stopFunItem2 = stopFunItemArr[0];
				stopFunItem1 = stopFunItemArr[1];
			}
			if (stopFunItem1.dictValue == '0') { //开启
			
				var itemData = JSON.parse(JSON.stringify(this.list));
				console.log(itemData);
				uni.navigateTo({
					url: '../myOrder/evaluate?order=' + this.qrVal + '&type=' + type
				});
			} else { //关闭
				let titleTips = stopFunItem2.dictValue
				uni.showToast({
					icon: 'none',
					title: titleTips,
					duration: 2000,
				})
			}
		},
		checkReturn() {
			var list = this.list;
			if (list === '') {
				return false;
			}
			let array = [];
			let num = 0;
			let isSample = 0;
			if (list.acceptDate) {
				const acceptDate = this.getUnixTime(list.acceptDate, 1) + 604800;
				const nowDate = this.getUnixTime(list.nowDate, 2);
				if (acceptDate < nowDate) {
					return false;
				}
			}
			this.goodsData.forEach((item, index) => {
				let multiple = 1;
				item.isRefund = false;
				item.remain = item.productsCount;
				if (item.suitCount) {
					multiple = parseInt(item.productsCount / item.suitCount);
				}
				let arr = [0];

				list.rejectInfo.forEach((item2, index) => {
					arr.push(item2.rejectNo);
					if (item2.customerServiceStatus !== 0 && item2.customerServiceStatus !== 9 && item2.customerServiceStatus !== 11) {
						if (item.isSample !== 0) {
							isSample += 1;
						}
						if (item.orderProductId == item2.orderProductId) {
							item.remain -= item2.productsCount;
							if (item.remain <= 0) {
								num += 1;
								item.isRefund = true;
							} else {
								item.isRefund = false;
							}
						}
					}
				});
				item.maxRejectNo = Math.max(...arr);
				if (item.suitCount) {
					item.remain = parseInt(item.remain / multiple);
				}
			});
			if (isSample > 0) {
				return false;
			}
			if (num === list.productInfo.length) {
				return false;
			} else {
				return true;
			}
		},
		applyService() {
			let stopFunItem1 = null; //当前对象
			let stopFunItem2 = null; //message对象
			let stopFunItemArr = this.stopFunctionArr.filter((item) => {
				return (item.dictLabel == 'function4' || item.dictLabel == 'message')
			});
			if (stopFunItemArr[0].dictLabel == 'function4') {
				stopFunItem1 = stopFunItemArr[0];
				stopFunItem2 = stopFunItemArr[1];
			} else {
				stopFunItem2 = stopFunItemArr[0];
				stopFunItem1 = stopFunItemArr[1];
			}
			
			if (stopFunItem1.dictValue == '0') { //开启
				let order = JSON.parse(JSON.stringify(this.list));
				let productInfo = [];
				let refundflag = false;
				if (order.orderStatus == 10) {
					refundflag = true;
				}
				for (let j = 0; j < order.productInfo.length; j += 1) {
					if (order.productInfo[j].isSample !== 0) {
						refundflag = true;
					}
				}
				for (let i = 0; i < order.productInfo.length; i += 1) {
					if (!order.productInfo[i].isRefund) {
						if (refundflag) {
							order.productInfo[i].disabled = true;
						} else {
							order.productInfo[i].disabled = false;
						}
						order.productInfo[i].checked = true;
						order.productInfo[i].singleCount = JSON.parse(JSON.stringify(order.productInfo[i].productsCount))
						if (order.productInfo[i].realAmount) {
							let num1 = this.moneyFormat(order.productInfo[i].realAmount / order.productInfo[i].productsCount);
							if(order.productInfo[i].remain==1){
								num1 = this.moneyFormat(order.productInfo[i].realAmount- order.productInfo[i].detailRejectAmount)
							}
							if (num1 < 0.01) {
								num1 = 0.01;
							}
							order.productInfo[i].productRealPrice = num1;
						} else {
							order.productInfo[i].productRealPrice = 0.0;
						}
						if (order.productInfo[i].suitRealAmount) {
							let num2 = this.moneyFormat(order.productInfo[i].suitRealAmount / order.productInfo[i].suitCount);
							if(order.productInfo[i].remain==1){
								num2 = this.moneyFormat(order.productInfo[i].suitRealAmount - order.productInfo[i].suitRejectAmount)
							}
							if (num2 < 0.01) {
								num2 = 0.01;
							}
							order.productInfo[i].suitRealPrice = num2;
						}
						productInfo.push(order.productInfo[i]);
					}
				}
				order.productInfo = JSON.parse(JSON.stringify(productInfo));
				uni.setStorageSync('returnOrder', order);
				//申请售后，tag为'1'表示申请售后，'2'表示重新申请
				uni.navigateTo({
					url: '../orderReturn/selectService?item=creat&status=' + order.orderStatus
				});
			} else { //关闭
				let titleTips = stopFunItem2.dictValue
				uni.showToast({
					icon: 'none',
					title: titleTips,
					duration: 2000,
				})
			}
				
		},
		jumpToService() {
			uni.navigateTo({
				url: '../customerService/customerService'
			});
		},
		timeLimit() {
			if (this.preSaleAfterPaymentStartTime && this.nowDate) {
				const startTime = this.getUnixTime(this.preSaleAfterPaymentStartTime, 3);
				const now = this.getUnixTime(this.nowDate, 4);
				if (startTime > now) {
					return false;
				} else {
					return true;
				}
			} else {
				return true;
			}
		},

		//1：待支付，2：已支付，3：已配货，4：待提货，5：已完成，6：已取消，

		getStatusLabel(id) {
			switch (id) {
				case 0:
					return '等待您付款';
				case 10:
					return '等待商家发货';
				case 30:
					return '卖家已发货';
				case 40:
					return '交易完成';
				case 50:
					return '部分退款';
				case 60:
					return '交易完成';
				case 70:
					return '交易已取消';
				case 90:
					return '订单退款';
				case 100:
					return '等待成团';
				default:
					return '';
			}
		},
		getReason(id) {
			switch (id) {
				case 0:
					return '逾期未付款,订单将自动取消';
				case 30:
					return '还剩余' + this.remainDay + '天' + this.remainHour + '时自动确认收货';
				default:
					return '';
			}
		},

		hide() {
			this.modalShow = false;
		},
		show() {
			let stopFunItem1 = null; //当前对象
			let stopFunItem2 = null; //message对象
			let stopFunItemArr = this.stopFunctionArr.filter((item) => {
				return (item.dictLabel == 'function2' || item.dictLabel == 'message')
			});
			if (stopFunItemArr[0].dictLabel == 'function2') {
				stopFunItem1 = stopFunItemArr[0];
				stopFunItem2 = stopFunItemArr[1];
			} else {
				stopFunItem2 = stopFunItemArr[0];
				stopFunItem1 = stopFunItemArr[1];
			}
			
			if (stopFunItem1.dictValue == '0') { //开启
				this.modalShow = true;
				this.modalContent = '您确定要取消订单吗？';
				this.cancelPostSale = '1';
			} else { //关闭
				let titleTips = stopFunItem2.dictValue
				uni.showToast({
					icon: 'none',
					title: titleTips,
					duration: 2000,
				})
			}
		},
		show2() {
			this.modalShow = true;
			this.modalContent = '您确定要收货吗？';
			this.cancelPostSale = '2';
		},
		handleClick(e) {
			let index = e.index;
			//撤销申请，放弃申请
			if (index == 1) {
				this.isLoading = true;
				var that = this;
				if (this.cancelPostSale == '1') {
					//点击确定按钮
					const params = {
						orderId: this.qrVal,
						orderStatus: 70
					};
					this.$http.editOrder(params).then(res => {
						if (res.status == 0) {
							uni.showToast({
								icon: 'none',
								title: '订单取消成功'
							});
							uni.navigateTo({
								url: '../myOrder/myOrder?tabIndex=0'
							});
						}
						this.isLoading = false;
					});
				} else if (this.cancelPostSale == '2') {
					//点击确定按钮
					const params = {
						orderId: this.qrVal,
						orderStatus: 40
					};
					this.$http.editOrder(params).then(res => {
						if (res.status == 0) {
							uni.showToast({
								icon: 'none',
								title: '收货成功'
							});
							uni.navigateTo({
								url: '../myOrder/myOrder?tabIndex=0'
							});
							this.isLoading = false;
						}
					});
				}
			}
			this.hide();
		},
		detail(item) {
			if (item.isSample !== 1) {
				if (item.suitId) {
					uni.navigateTo({
						url: '../goodsDetails/goodsDetails?&suitId=' + item.suitId
					});
				} else {
					uni.navigateTo({
						url: '../goodsDetails/goodsDetails?&productId=' + item.productId
					});
				}
			}
		},
		getOrderDetail() {
			this.isLoading = true;
			const params = {
				orderId: this.qrVal
			};

			this.$http.getOrderDetail(params).then(res => {
				if (res.status == 0) {
					this.list = res.data;
					if (res.data.deliveryDate) {
						const deliveryDate = this.getUnixTime(res.data.deliveryDate, 5) + 691200;
						const nowDate = this.getUnixTime(res.data.nowDate, 6);
						this.remainDay = parseInt((deliveryDate - nowDate) / 86400);
						const float = (deliveryDate - nowDate) % 86400;
						this.remainHour = parseInt(float / 3600);
					}
					this.couponName = res.data.couponName;
					this.couponPacleName = res.data.couponPacleName;
					this.goodsData = res.data.productInfo;
					this.preSaleFlag = this.goodsData[0].preSaleFlag;
					let item = this.list;
					let suitIdArr = [];
					let index = [];
					for (let i = 0; i < item.productInfo.length; i += 1) {
						item.productInfo[i].suitNum = 0;
						if (item.productInfo[i].suitId) {
							let id = item.productInfo[i].suitId + item.productInfo[i].isSample;
						if (!suitIdArr.includes(id)) {
							item.productInfo[i].suitInfo = [];
							item.productInfo[i].once = parseInt(item.productInfo[i].productsCount / item.productInfo[i].suitCount);
							item.productInfo[i].suitInfo.push({
								productThumbnailImageUrl: JSON.parse(JSON.stringify(item.productInfo[i].productThumbnailImageUrl)),
								productName: JSON.parse(JSON.stringify(item.productInfo[i].productName)),
								productsCount: JSON.parse(JSON.stringify(item.productInfo[i].once))
							});
							item.productInfo[i].isSuit = true;
							index.push({
								suitId: id,
								index: i
							});
							item.productInfo[i].suitRealAmount = JSON.parse(JSON.stringify(item.productInfo[i].realAmount));
							item.productInfo[i].suitShow = false;
							item.productInfo[i].suitNum += 1;
							item.productInfo[i].suitRejectAmount = JSON.parse(JSON.stringify(item.productInfo[i].detailRejectAmount));
							suitIdArr.push(id);
						} else if (suitIdArr.includes(id)) {
							let n = 0;
							for (let j = 0; j < index.length; j += 1) {
								if (index[j].suitId === id) {
									n = index[j].index;
								}
							}
							item.productInfo[i].once = parseInt(item.productInfo[i].productsCount / item.productInfo[i].suitCount);
							item.productInfo[n].suitInfo.push({
								productThumbnailImageUrl: JSON.parse(JSON.stringify(item.productInfo[i].productThumbnailImageUrl)),
								productName: JSON.parse(JSON.stringify(item.productInfo[i].productName)),
								productsCount: JSON.parse(JSON.stringify(item.productInfo[i].once))
							});
							item.productInfo[n].suitRealAmount += item.productInfo[i].realAmount;
							item.productInfo[n].suitRejectAmount += item.productInfo[i].detailRejectAmount
							item.productInfo[i].suitNum += 1;
							item.productInfo[i].show = 2;
						}
						}
					}

					this.version = res.data.version;
					this.status = res.data.orderStatus;
					this.realAmount = res.data.realAmount;
					this.orderSerial = res.data.orderSerial;
					this.createTime = res.data.createTime;
					this.payDate = res.data.payDate;
					this.deliveryDate = res.data.deliveryDate;
					this.pickupName = res.data.buyerInfo.receiveName;
					this.pickupMobile = res.data.buyerInfo.receiveTel;
					this.areaLevel1 = res.data.buyerInfo.areaLevel1;
					this.areaLevel2 = res.data.buyerInfo.areaLevel2;
					this.areaLevel3 = res.data.buyerInfo.areaLevel3;
					this.addCommentFlg = res.data.addCommentFlg;
					this.addressDet = res.data.buyerInfo.receiveAddress;
					this.preSaleAfterPaymentStartTime = res.data.preSaleAfterPaymentStartTime;
					this.preSaleAfterPaymentEndTime = res.data.preSaleAfterPaymentEndTime;
					this.nowDate = res.data.nowDate;
					this.orderPreSaleStatus = res.data.orderPreSaleStatus;
					if (this.goodsData[0].preSaleType == 1) {
						this.depositPrice = this.moneyFormat(res.data.deposit - res.data.logisticsCost);
					} else {
						this.depositPrice = res.data.deposit;
					}

					this.buyComment = res.data.buyerInfo.buyerComment;
					this.orderAmount = 0;
					this.productAmount = 0;
					for (let i = 0; i < this.goodsData.length; i += 1) {
						if (this.goodsData[i].isSample === 0) {
							this.preSaleAfterPaymentStartDay = this.goodsData[i].preSaleAfterPaymentStartDay;
							this.preSaleAfterPaymentDateType = this.goodsData[i].preSaleAfterPaymentDateType;
							this.orderAmount += this.goodsData[i].realAmount;
							this.productAmount += this.goodsData[i].productDiscountPrice * this.goodsData[i].productsCount;
						}
					}
					if (this.goodsData[0].preSaleType != 1) {
						this.balance = this.moneyFormat(res.data.retainage - res.data.logisticsCost);
					} else {
						this.balance = res.data.retainage;
					}
					if (this.goodsData[0].preSaleFlag == 1) {
						this.balanceTime = this.getbalanceTime();
						this.deliverTime = this.deliveryTime(this.list);
					}

					if (res.data.couponPrice) {
						this.couponPrice = res.data.couponPrice;
					}
					this.discountAmount = res.data.discountAmount;

					if (res.data.logisticsCost == null || res.data.logisticsCost == '') {
						this.logisticsCost = '免运费';
						this.expressFee = 0;
					} else {
						this.expressFee = res.data.logisticsCost;
						this.logisticsCost = '￥' + res.data.logisticsCost;
					}
				}
				this.isLoading = false;
			});
		},
		getbalanceTime() {
			if (this.preSaleAfterPaymentDateType == 1) {
				if (this.orderPreSaleStatus == 1) {
					if (this.preSaleAfterPaymentStartDay) {
						return '付定金' + this.preSaleAfterPaymentStartDay + '天后开始';
					} else {
						return '付定金后';
					}
				} else {
					const now = this.getUnixTime(this.nowDate, 7);
					const start = this.getUnixTime(this.preSaleAfterPaymentStartTime, 8);
					if (start > now) {
						const text = this.changeTime(this.preSaleAfterPaymentStartTime);
						return text + '后开始';
					} else {
						const text2 = this.changeTime(this.preSaleAfterPaymentEndTime);
						return '请在' + text2 + '之前支付尾款';
					}
				}
			} else {
				const now = this.getUnixTime(this.nowDate, 9);
				const start = this.getUnixTime(this.preSaleAfterPaymentStartTime, 10);
				if (start > now) {
					const text = this.changeTime(this.preSaleAfterPaymentStartTime);
					return text + '后开始';
				} else {
					const text2 = this.changeTime(this.preSaleAfterPaymentEndTime);
					return '请在' + text2 + '之前支付尾款';
				}
			}
		},
		getUnixTime(dateStr, id) {
			var newstr = dateStr.replace(/-/g, '/');
			var date = new Date(newstr);
			var time_str = date.getTime().toString();
			return parseInt(time_str.substr(0, 10));
		},
		changeTime(time) {
			const date = time.split(' ');
			const month = date[0].split('-')[1];
			const day = date[0].split('-')[2];
			const hour = date[1].split(':')[0];
			const min = date[1].split(':')[1];
			return month + '月' + day + '日 ' + hour + ':' + min;
		},
		//下单时间 与 现在的时间差
		tab(date) {
			if (date) {
				let datatime = date.replace(/\-/g, '/');
				var oDate1 = new Date(datatime);
				var oDate2 = new Date();
				var time = oDate2.getTime() - oDate1.getTime();
				this.paymentTime = 1800 - Math.floor(time / 1000);
			} else {
				return;
			}
		},
		endOfTime() {
			this.status = 6;
			this.getOrderDetail(this.orderId);
		},
		getlogistics() {
			uni.navigateTo({
				url: '../logistics/logistics?orderId=' + this.qrVal
			});
		},
		getAfterPaymentTime(item, endTime) {
			if (this.orderPreSaleStatus == 1) {
				return this.balanceTime;
			} else {
				if (item.preSaleAfterPaymentDateType === 1) {
					return `请在${this.changeTime(endTime)}之前支付尾款`;
				} else {
					return `请在${this.changeTime(item.preSaleAfterPaymentFixedEndTime)}之前支付尾款`;
				}
			}
		},
		deliveryTime(list) {
			if (list.preSaleDeliveryTimeText.indexOf('年') == -1) {
				return list.preSaleDeliveryTimeText;
			} else {
				return list.preSaleDeliveryTimeText.split('年')[1];
			}
		},
		goPay() {
			var goodsList = [];
			let totalCount = 0;
			let totalPrice = 0;
			this.goodsData.forEach((item, index) => {
				if (item.isSample == 0 && item.preSaleFlag == 0) {
					if (item.isSuit && item.show !== 2) {
						totalCount += item.suitCount;
						totalPrice += item.suitRealAmount;
					} else if (item.show !== 2) {
						totalCount += item.productsCount;
						totalPrice += item.productsCount * item.productDiscountPrice;
					}
					goodsList.push({
						specificationId: item.specificationId,
						productsCount: item.productsCount,
						hasActive: true,
						myOrder: 1,
						orderId: this.orderSerial,
						buyComment: this.buyComment
					});
				} else if (item.preSaleFlag == 1) {
					const afterPaymentTime = this.getAfterPaymentTime(this.list.productInfo[0], this.list.preSaleAfterPaymentEndTime);
					totalCount += item.productsCount;
					totalPrice += item.productsCount * item.productDiscountPrice;
					goodsList.push({
						specificationId: item.specificationId,
						productsCount: item.productsCount,
						myOrder: 1,
						orderId: this.orderSerial,
						buyComment: this.buyComment,
						preSaleOrderStatus: this.orderPreSaleStatus,
						finalPay: this.list.retainage,
						deposit: this.list.deposit,
						preSaleFlag: 1,
						afterPaymentTime: afterPaymentTime,
						preSaleDeliveryTimeText: this.deliveryTime(this.list)
					});
				}
			});
			uni.setStorageSync('carGoodsList', goodsList);
			let couponPrice = 0;
			if (this.couponPrice != null) {
				couponPrice = this.couponPrice;
			}
			let logisticsCost = 0;
			if (this.expressFee > 0) {
				logisticsCost = this.expressFee;
			}
			const item = {
				productInfo: this.goodsData,
				discountAmount: this.discountAmount,
				couponAmount: this.couponPrice,
				couponName: this.couponName,
				couponPacleName:this.couponPacleName,
				amount: this.realAmount,
				expressFee: logisticsCost,
				totalCount: totalCount,
				totalPrice: totalPrice,
				preSaleType: this.goodsData[0].preSaleType
			};
			uni.setStorageSync('productList', item);
			uni.navigateTo({
				url: '../submitOrder/submitOrder'
			});
		}
	}
};
</script>

<style lang="scss">
.service {
	width: 100%;
	height: 75rpx;
	background-color: #ffffff;
	margin-top: 5rpx;
	text-align: center;
	line-height: 75rpx;
	.iconkefu {
		display: inline-block;
		margin-right: 10px;
	}
	.serviceWord {
		display: inline-block;
	}
}
.tui-operation-item {
	position: absolute;
	left: 15rpx;
	top: 14rpx;
	.iconkefu {
		text-align: center;
	}
}
.tui-bg-img {
	position: absolute;
	width: 100%;
	height: 8rpx;
	left: 0;
	bottom: 0;
	background: url('')
		repeat;
}
.redRow {
	color: #e96d71 !important;
}

.tui-padding {
	box-sizing: border-box;
}
.imgMark {
	position: absolute;
	width: 100rpx !important;
	height: 100rpx !important;
	top: 0px;
	left: 12rpx;
	z-index: 99999;
}
.tui-flex {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 26rpx;
}

.pickupMobile {
	color: #aaa;
	padding-left: 15rpx;
	font-weight: normal;
}
.container {
	padding-bottom: 20rpx;
}

.tui-order-header {
	width: 100%;
	height: 160rpx;
	position: relative;
}

.tui-img-bg {
	width: 100%;
	height: 160rpx;
}

.tui-header-content {
	width: 100%;
	height: 160rpx;
	position: absolute;
	z-index: 10;
	left: 0;
	top: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 70rpx;
	box-sizing: border-box;
}

.tui-status-text {
	font-size: 36rpx;
	line-height: 36rpx;
	color: #fefefe;
}

.tui-reason {
	font-size: 24rpx;
	line-height: 24rpx;
	color: rgba(254, 254, 254, 0.75);
	padding-top: 15rpx;
	display: flex;
	align-items: center;
}

.tui-reason-text {
	padding-right: 12rpx;
}

.tui-status-img {
	width: 80rpx;
	height: 80rpx;
	display: block;
	color: #fff;
	font-size: 70rpx;
	text-align: center;
	line-height: 80rpx;
}

.tui-flex-box {
	width: 100%;
	display: flex;
	align-items: center;
}

.tui-icon-img {
	width: 44rpx;
	height: 44rpx;
	flex-shrink: 0;
}

.tui-logistics {
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0 24rpx 0 20rpx;
	box-sizing: border-box;
}

.tui-logistics-text {
	font-size: 28rpx;
	line-height: 32rpx;
}

.tui-logistics-time {
	font-size: 24rpx;
	line-height: 24rpx;
	padding-top: 16rpx;
	color: #666;
}

.tui-addr {
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding-left: 20rpx;
	box-sizing: border-box;
}

.tui-addr-userinfo {
	font-size: 30rpx;
	line-height: 30rpx;
	font-weight: bold;
}

.tui-addr-text {
	font-size: 24rpx;
	line-height: 30rpx;
	padding-top: 16rpx;
}

.tui-addr-tel {
	padding-left: 40rpx;
}

.tui-order-item {
	margin-top: 20rpx;
	border-radius: 10rpx;
	overflow: hidden;
}

.tui-goods-title {
	width: 100%;
	font-size: 28rpx;
	line-height: 28rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.tui-goods-item {
	width: 100%;
	padding: 20rpx 30rpx;
	box-sizing: border-box;
	display: flex;
	justify-content: space-between;
}

.goods-item-btn {
	position: absolute;
	right: 30rpx;
	bottom: 20rpx;
}

.tui-goods-img {
	width: 180rpx;
	height: 180rpx;
	display: block;
	flex-shrink: 0;
}

.tui-goods-center {
	flex: 1;
	padding: 20rpx 8rpx;
	box-sizing: border-box;
}

.tui-goods-name {
	max-width: 310rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	font-size: 26rpx;
	line-height: 32rpx;
}

.tui-goods-attr {
	font-size: 22rpx;
	color: #888888;
	line-height: 32rpx;
	padding-top: 20rpx;
	word-break: break-all;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.tui-price-right {
	text-align: right;
	font-size: 24rpx;
	color: #888888;
	line-height: 30rpx;
	padding-top: 20rpx;
}

.yxf-color-red {
	color: $red;
}

.tui-goods-price {
	width: 100%;
	display: flex;
	align-items: flex-end;
	justify-content: flex-end;
	font-size: 24rpx;
}

.tui-size-24 {
	font-size: 24rpx;
	line-height: 24rpx;
}

.tui-price-large {
	font-size: 32rpx;
	line-height: 30rpx;
}

.tui-goods-info {
	width: 100%;
	padding: 30rpx;
	box-sizing: border-box;
	background: #fff;
}

.tui-price-flex {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.tui-size24 {
	padding-bottom: 20rpx;
	font-size: 24rpx;
	line-height: 24rpx;
	color: #888;
}

.tui-size32 {
	font-size: 32rpx;
	line-height: 32rpx;
	font-weight: 500;
}

.tui-pbtm20 {
	padding-bottom: 20rpx;
}

.tui-flex-shrink {
	flex-shrink: 0;
}

.tui-primary-color {
	//color: $themeColor;
}

.tui-order-info {
	margin-top: 20rpx;
}

.tui-order-title {
	width: 100%;
	position: relative;
	font-size: 28rpx;
	line-height: 28rpx;
	padding-left: 12rpx;
	box-sizing: border-box;
}

.tui-order-title::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	//border-left: 4rpx solid $themeColor;
	height: 100%;
}

.tui-order-content {
	width: 100%;
	padding: 24rpx 30rpx;
	box-sizing: border-box;
	background: #fff;
	font-size: 24rpx;
	line-height: 30rpx;
}

.tui-order-flex {
	display: flex;
	padding-top: 18rpx;
	width: 100%;
	line-height: 24rpx;
	// height: 30rpx;

	.yxf-item-reason {
		width: 100%;
		box-sizing: border-box;
		padding: 10rpx;
		border-radius: 20rpx;
		border: 2rpx solid $borderColor;

		.reason-text {
			margin: 20rpx 1%;
			color: #aaa;
		}

		.reason-img {
			width: 31.3%;
			float: left;
			margin: 10rpx 1%;

			image {
				width: 100%;
				height: 200rpx;
			}
		}
	}
}

.tui-order-flex:first-child {
	padding-top: 0;
}

.tui-item-title {
	width: 132rpx;
	height: 28rpx;
	flex-shrink: 0;
}

.tui-item-content {
	color: #666;
}

.tui-safe-area {
	height: 200rpx;
	padding-bottom: env(safe-area-inset-bottom);
}
// .tui-safe {
// 	height: 100rpx;
// }

.tui-order-btn {
	justify-content: flex-end;
}

.tui-btn-mr {
	margin-right: 30rpx;
	padding: 15rpx 0;
}

.take-goods-wrap {
	width: 100%;
	text-align: center;
	display: flex;
	flex-direction: column;

	view {
		width: 100%;
		display: block;
	}

	.title {
		font-size: 26rpx;
		margin-bottom: 20rpx;
	}

	.qr-code {
		.tui-goods-img {
			width: 200rpx;
			height: 200rpx;
			margin: 0 auto;
		}
	}

	.qr-number {
		//color:$themeColor;
		margin-top: 20rpx;
		font-size: 28rpx;
	}
}

.yxf-service-content {
	.tui-item-title {
		width: 164rpx;
	}
}
</style>
